home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / Macintosh Common Lisp Related / User Contributions / zebu v3.3.3 (LALR parser) / zebu-compile.lisp < prev    next >
Encoding:
Text File  |  1994-09-12  |  3.4 KB  |  104 lines  |  [TEXT/ttxt]

  1. ; -*- mode:     CL -*- ----------------------------------------------------- ;
  2. ; File:         zebu-compile.lisp
  3. ; Description:  apply the grammar-compiler
  4. ; Author:       Joachim H. Laubsch
  5. ; Created:       6-Nov-90
  6. ; Modified:     Tue Aug  2 16:20:04 1994 (Joachim H. Laubsch)
  7. ; Language:     CL
  8. ; Package:      ZEBU
  9. ; Status:       Experimental (Do Not Distribute) 
  10. ; RCS $Header: $
  11. ;
  12. ; (c) Copyright 1990, Hewlett-Packard Company
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ; Revisions:
  15. ; RCS $Log: $
  16. ; 25-Apr-91 (Joachim H. Laubsch)
  17. ;  introduced *WARN-CONFLICTS* to shut up warnings
  18.  
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20.  
  21. (in-package "ZEBU")
  22.  
  23. ;; whether warnings about action-conflicts are printed at compile time
  24. (defvar *warn-conflicts* nil)
  25. (defvar *compiler-grammar* *null-grammar*
  26.   "The grammar that the Zebu Compiler uses when reading a grammar.
  27. By default this is the Null-Grammar.")
  28.  
  29. (defun zebu-compile-file (grammar-file
  30.               &key (grammar *null-grammar*)
  31.               output-file
  32.               verbose
  33.               (compile-domain t))
  34.   "Compiles the LALR(1) grammar in file GRAMMAR-FILE."
  35.   (assert (probe-file (setq grammar-file
  36.                         (merge-pathnames grammar-file
  37.                                          (merge-pathnames
  38.                       (make-pathname :type "zb")))))
  39.       (grammar-file)
  40.       "Cannot find grammar file: ~A" grammar-file)
  41.   (setq output-file
  42.     (let ((tab (make-pathname :type "tab")))
  43.           (if output-file    
  44.           (merge-pathnames (pathname output-file) tab)
  45.             (merge-pathnames tab grammar-file))))
  46.   (when (probe-file output-file) (delete-file output-file))
  47.   (format t "~%; Zebu Compiling (Version ~A)~%; ~S to ~S~%"
  48.       *zebu-version* grammar-file output-file)
  49.   (let ((*warn-conflicts* verbose))
  50.     (compile-lalr1-grammar grammar-file
  51.                :output-file output-file
  52.                :grammar grammar
  53.                :verbose verbose
  54.                :compile-domain compile-domain)))
  55.  
  56.  
  57. ;----------------------------------------------------------------------------;
  58. ; compile-from-command-line
  59. ;--------------------------
  60. ; call zebu-compile-file with a command-line-argument
  61. #+LUCID
  62. (defun compile-from-command-line ()
  63.   (let ((*default-pathname-defaults*
  64.      (make-pathname :directory
  65.             (pathname-directory (working-directory))
  66.             :type "zb"))
  67.     (ifile (command-line-argument 1))
  68.     ofile
  69.     verbose
  70.     compile-domain)
  71.     (if (null ifile)
  72.     (Warn "No input file specified!")
  73.       (progn
  74.     (do* ((a 2 (1+ a))
  75.           (arg (command-line-argument a) (command-line-argument a)))
  76.          ((null arg))
  77.       (cond ((equalp arg "-v") (setq verbose t))
  78.         ((equalp arg "-d") (setq compile-domain t))
  79.         ((equalp arg "-r") (load (command-line-argument (incf a))))
  80.         ((= a 2) (setq ofile arg))))
  81.     (apply #'zebu-compile-file ifile
  82.            :verbose verbose
  83.            :compile-domain compile-domain
  84.            (when ofile
  85.          `(:output-file ,ofile)))))
  86.     (terpri)
  87.     (quit)))
  88.  
  89.  
  90. ;----------------------------------------------------------------------------;
  91. ; zebu-top
  92. ;---------
  93. ; interactive compiler invocation
  94.  
  95. (defun zebu-compile-top ()
  96.   (format t "~&Enter the name of a Zebu Grammar file to compile: ")
  97.   (let ((ifile (read-line t)))
  98.     (zebu-compile-file ifile)))
  99.  
  100. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  101. ;;                            End of zebu-compile.l
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103.